<!--
  Copyright 2018 Google Inc., PhantomJS Authors All rights reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 -->

<html>
<link rel="shortcut icon" href="favicon.ico" sizes="256x256" />
<style>
body {
  color: #ddd;
  display: flex;
  justify-content: center;
  background-color: #2b2e3b;
  opacity: 0;
  transition: opacity 2s;
  font-family: Roboto;
  overflow: hidden;
}

.content {
  display: flex;
  flex-direction: column;
  flex: auto;
  justify-content: center;
}

.heading {
  font-size: 36px;
  text-align: center;
  margin: 25px 0;
}

#grids {
  margin-top: 30px;
  color: #ddd;
  display: grid;
  grid-template-columns: 33% 33% 33%;
  grid-gap: 40px;
  margin: 25px;
  overflow: hidden;
}

.grid-placeholder {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px;
}

.grid {
  flex: auto;
  display: grid;
  grid-template-columns: 1fr 4fr;
  grid-gap: 4px;
}

.blur {
  /**filter: blur(7px);*/
}

.value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header {
  font-weight: bold;
  grid-column: span 2;
  border-bottom: 1px solid #999;
}

/* roboto-regular - latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: url('fonts/roboto-v18-latin-regular.woff2') format('woff2');
}
</style>

<title>Systeminfo App</title>
<script>
async function onload() {
  const data = await systeminfo();
  const grids = document.getElementById('grids');
  const blur = new Set(['serial', 'uuid', 'sku', 'hostname']);
  const keys = Object.keys(data).sort();
  for (const type of keys) {
    const info = data[type];
    const placeholder = createChild(grids, 'div', 'grid-placeholder');
    const grid = createChild(placeholder, 'div', 'grid');
    createChild(grid, 'div', 'header').textContent = type;
    const infos = Object.keys(info).sort();
    for (const key of infos) {
      if (typeof info[key] === 'object') continue;
      createChild(grid, 'div').textContent = key;
      const value = createChild(grid, 'div', 'value');
      value.textContent = info[key];
      if (blur.has(key))
        value.classList.add('blur');
    }
  }
  document.body.style.opacity = 1;
}

function createChild(parent, tag, className) {
  const elem = document.createElement(tag);
  if (className)
    elem.className = className;
  parent.appendChild(elem);
  return elem;
}

</script>
<body onload="onload()">
  <div class="content">
    <div class="heading">Welcome to Carlo!</div>
    <div id="grids"></div>
  </div>
</body>

</html>
